package nxu.it.movieapi.service.pg.dao;

import nxu.it.api.model.Comment;
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.statement.SqlQuery;

import java.util.List;

public interface CommentPgDao {
    @SqlQuery("SELECT * FROM comment WHERE user_id = :userId ORDER BY id LIMIT :size OFFSET :offset")
    @RegisterBeanMapper(Comment.class)
    List<Comment> findByUserId(@Bind("userId") Integer userId, @Bind("size") int size, @Bind("offset") int offset);

    @SqlQuery("SELECT COUNT(*) FROM comment WHERE user_id = :userId")
    long countByUserId(@Bind("userId") Integer userId);

    @SqlQuery("SELECT * FROM comment WHERE movie_id = :movieId ORDER BY id LIMIT :size OFFSET :offset")
    @RegisterBeanMapper(Comment.class)
    List<Comment> findByMovieId(@Bind("movieId") Integer movieId, @Bind("size") int size, @Bind("offset") int offset);

    @SqlQuery("SELECT COUNT(*) FROM comment WHERE movie_id = :movieId")
    long countByMovieId(@Bind("movieId") Integer movieId);
}
